package com.cacshanghai.cac_oa_client.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.cacshanghai.cac_oa_client.R;

import fr.castorflex.android.verticalviewpager.VerticalViewPager;


/**
 * Created by geyh on 2016/5/25.
 */
public class DailyActivity extends BaseActivity {

    public VerticalViewPager verticalViewPager;
    private DailyCalendarFragment dailyCalendarFragment;
    private DailyFormFragment dailyFormFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_daily);
        setTitle(getString(R.string.my_daily) + "(葛仪豪)");
        setBack();

        dailyCalendarFragment = new DailyCalendarFragment();
        dailyFormFragment = new DailyFormFragment();
        initViewPager();
    }

    private void initViewPager() {
        verticalViewPager = (VerticalViewPager) findViewById(R.id.verticalviewpager);
        verticalViewPager.setAdapter(new FragmentAdapter(getSupportFragmentManager()));
    }

    class FragmentAdapter extends FragmentPagerAdapter {

        public FragmentAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            switch (position) {
                case 0:
                    return dailyCalendarFragment;
                case 1:
                    return dailyFormFragment;
                default:
                    break;
            }
            return null;
        }

        @Override
        public int getCount() {
            return 2;
        }
    }


    @Override
    public void onBackPressed() {
        if (verticalViewPager.getCurrentItem() != 0) {
            verticalViewPager.setCurrentItem(0, true);
        } else {
            super.onBackPressed();
        }
    }
}
